'use strict';
exports.main = async (event, context) => {
  const db = uniCloud.database()
  
  try {
    // 获取当前用户ID
    const { OPENID, UNIONID, APPID } = context
    if (!OPENID) {
      return {
        code: 403,
        message: '未登录'
      }
    }
    
    const { type, content, images, contact } = event
    if (!type || !content) {
      return {
        code: 400,
        message: '缺少必要参数'
      }
    }
    
    // 创建反馈记录
    const result = await db.collection('feedback').add({
      user_id: OPENID,
      type,
      content,
      images: images || [],
      contact,
      status: 'pending',
      createTime: Date.now()
    })
    
    return {
      code: 200,
      message: '提交成功',
      data: result
    }
    
  } catch (error) {
    console.error('提交反馈失败:', error)
    return {
      code: 500,
      message: error.message || '提交失败'
    }
  }
} 